package com.usesion.controller;

import com.usesion.base.controller.BaseController;
import com.usesion.config.ReportConfig;
import com.usesion.entity.Menu;
import com.usesion.entity.User;
import com.usesion.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 首页 业务处理
 * @author XT
 */
@Controller
public class IndexController extends BaseController
{
    @Autowired
    private MenuService menuService;
    @Autowired
    private ReportConfig reportConfig;
    /**
     * 首页
     * @param model
     * @return
     */
    @GetMapping("/index")
    public String index(Model model) {
        User user = getUser();
        List<Menu> menus = menuService.selectMenusByUserId(user.getId());
        model.addAttribute("menus", menus);
        model.addAttribute("user", user);
        model.addAttribute("copyrightYear", reportConfig.getCopyrightYear());
        return "index";
    }

    /**
     * 系统介绍
     * @param model
     * @return
     */
    @GetMapping("/system/main")
    public String main(Model model) {
        model.addAttribute("version", "1.0");
        return "main";
    }

}
